﻿using System;
using HossMvp.Core;
using Sample.Properties;

namespace Sample.Models
{
    public class PreferencesModel : AbstractModel
    {
        public PreferencesModel(AbstractModelManager manager, string name, IContentProvider contents)
            : base(manager, name, contents)
        {
        }

        public class PreferencesContentProvider : AbstractContentProvider
        {
            public PreferencesContentProvider(NameDecorator decorator)
                : base(decorator)
            {
                //this.RegisterAction("LoadPreferences", this.LoadPreferences);
                //this.RegisterAction("SavePreferences", this.SavePreferences);
                this.RegisterActions();
            }

            private ActionResult SavePreferences(ActionContext context)
            {
                var section = context.Get<string>("section");
                switch (section)
                {
                    case "General":
                        Settings.Default.Preferences_General_Language = context.Get<string>("locallization");
                        Settings.Default.Preferences_General_MainToolbar = context.Get<bool>("maintoolbar");
                        Settings.Default.Preferences_General_MainMenu = context.Get<bool>("mainmenu");
                        Settings.Default.Preferences_General_Statusbar = context.Get<bool>("statusbar");
                        break;
                    case "Editor":
                        return new ActionResult();
                    case "Plugins":
                        return new ActionResult();
                }

                Settings.Default.Save();
                return null;
            }

            private ActionResult LoadPreferences(ActionContext context)
            {
                var section = context.Get<string>("section");
                switch (section)
                {
                    case "General":
                        var result = new ActionResult()
                            .WithProperty("locallization", Settings.Default.Preferences_General_Language)
                            .WithProperty("maintoolbar", Settings.Default.Preferences_General_MainToolbar)
                            .WithProperty("mainmenu", Settings.Default.Preferences_General_MainMenu)
                            .WithProperty("statusbar", Settings.Default.Preferences_General_Statusbar);
                        return result;
                    case "Editor":
                        return new ActionResult();
                    case "Plugins":
                        return new ActionResult();
                }

                return null;
            }
        }
    }
}
